package 剑指offer;

public class M4 {
    public int singleNumber(int[] nums) {
        int[] data=new int[32];
        int lezero=0;
        for (int num : nums) {
            int flag=0;
            long middle=num;
            if (num<0) {
                middle=-middle;
                lezero+=1;
            }
            while (middle!=0) {
                data[flag++]+=middle%2;
                middle>>=1;
            }
        }
        int res=0;
        int middle=1;
        for (int datum : data) {
            if (datum%3==1) {
                res+=middle;
            }
            middle<<=1;
        }
        return lezero%3==0? res:-res;
    }
}
